import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    token: '',
    user: null,
    userId: null,
    is_counselor: false,
    is_admin: false,
    is_assistantn: false,
  }),
  actions: {
    setToken(token) {
      this.token = token
    },
    setUser(user) {
      this.user = user
      this.userId = user?.id || null
    },
    setCounselor(is_counselor) {
      this.is_counselor = is_counselor
    },
    setAdmin(is_admin) {
      this.is_admin = is_admin
    },
    setAssistantn(is_assistantn) {
      this.is_assistantn = is_assistantn
    },
    /* //更新用户信息
    updateUserInfo(userInfo) {
      this.token = userInfo.token
      this.is_counselor = userInfo.is_counselor
      this.is_admin = userInfo.is_admin
      this.is_assistantn=userInfo.is_assistantn
    },*/

    clearUser() {
      this.token = ''
      this.user = null
      this.userId = null
      this.is_counselor = null
      this.is_admin = null
      this.is_assistantn = null
    },
  },
  persist: {
    enabled: true,
    afterRestore: (ctx) => {
      console.log('Restored userId:', ctx.store.userId)
      console.log('Restored is_counselor:', ctx.store.is_counselor)
      console.log('Restored is_admin:', ctx.store.is_admin)
    },
  },
})
